package com.sunriz.javafx.views;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Region;
import javafx.stage.Stage;

import java.io.IOException;

public class MainControllerBackups {
    @FXML
    private Label welcomeText;

    @FXML
    protected void onHelloButtonClick(){
        welcomeText.setText("Welcome to JavaFX Application!");
    }

    @FXML
    protected void openSecondShow(){
        try {
            // 加载第二个界面的 FXML 文件
            FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/sunriz/javafx/second-view.fxml"));
            // 加载第二个界面的根节点
            Region secondShowRoot = loader.load();

            // 获取当前窗口
            Stage currentStage = (Stage) welcomeText.getScene().getWindow();

            currentStage.setScene(new Scene(secondShowRoot));
            currentStage.show();

            // 关闭当前窗口
//            Stage currentStage = (Stage) welcomeText.getScene().getWindow();  // 获取当前窗口
//            currentStage.close();  // 关闭当前窗口
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @FXML
    public void RealTimeDataExample() {
        RealTimeDataExampleController realTimeDataExampleController = new RealTimeDataExampleController();

        // 获取当前窗口
        Stage currentStage = (Stage) welcomeText.getScene().getWindow();
        realTimeDataExampleController.start(currentStage);
    }

    @FXML
    public void openScadaView() {
        try {
            // 加载scada界面的 FXML 文件
            FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/sunriz/javafx/scada-view.fxml"));
            // 加载第二个界面的根节点
            Region secondShowRoot = loader.load();

            // 获取当前窗口
            Stage currentStage = (Stage) welcomeText.getScene().getWindow();
            currentStage.setScene(new Scene(secondShowRoot));
            currentStage.show();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}